home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / JFC.bin / Highlighter.java < prev    next >
Text File  |  1998-06-30  |  4KB  |  150 lines

  1. /*
  2.  * @(#)Highlighter.java    1.14 98/04/09
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. import java.awt.Color;
  23. import java.awt.Graphics;
  24. import java.awt.Shape;
  25.  
  26. /**
  27.  * An interface for an object that allows one to mark up the background
  28.  * with colored areas.  
  29.  *
  30.  * @author  Timothy Prinzing
  31.  * @version 1.14 04/09/98
  32.  */
  33. public interface Highlighter {
  34.  
  35.     /**
  36.      * Called when the UI is being installed into the
  37.      * interface of a JTextComponent.  This can be used
  38.      * to gain access to the model that is being navigated
  39.      * by the implementation of this interface. 
  40.      *
  41.      * @param c the JTextComponent editor
  42.      */
  43.     public void install(JTextComponent c);
  44.  
  45.     /**
  46.      * Called when the UI is being removed from the
  47.      * interface of a JTextComponent.  This is used to 
  48.      * unregister any listeners that were attached.
  49.      *
  50.      * @param c the JTextComponent editor
  51.      */
  52.     public void deinstall(JTextComponent c);
  53.  
  54.     /**
  55.      * Renders the highlights.
  56.      *
  57.      * @param g the graphics context.
  58.      */
  59.     public void paint(Graphics g);
  60.  
  61.     /**
  62.      * Adds a highlight to the view.  Returns a tag that can be used 
  63.      * to refer to the highlight.
  64.      *
  65.      * @param p0 the beginning of the range >= 0
  66.      * @param p1 the end of the range >= p0
  67.      * @param p the painter to use for the actual highlighting
  68.      * @return an object that refers to the highlight
  69.      * @exception BadLocationException for an invalid range specification
  70.      */
  71.     public Object addHighlight(int p0, int p1, HighlightPainter p) throws BadLocationException;
  72.  
  73.     /**
  74.      * Removes a highlight from the view.
  75.      *
  76.      * @param tag  which highlight to remove
  77.      */
  78.     public void removeHighlight(Object tag);
  79.  
  80.     /**
  81.      * Removes all highlights this highlighter is responsible for.
  82.      */
  83.     public void removeAllHighlights();
  84.  
  85.     /**
  86.      * Changes the given highlight to span a different portion of 
  87.      * the document.  This may be more efficient than a remove/add
  88.      * when a selection is expanding/shrinking (such as a sweep
  89.      * with a mouse) by damaging only what changed.
  90.      *
  91.      * @param tag  which highlight to change
  92.      * @param p0 the beginning of the range >= 0
  93.      * @param p1 the end of the range >= p0
  94.      * @exception BadLocationException for an invalid range specification
  95.      */
  96.     public void changeHighlight(Object tag, int p0, int p1) throws BadLocationException;
  97.  
  98.     /**
  99.      * Fetches the current list of highlights.
  100.      *
  101.      * @return the highlight list
  102.      */
  103.     public Highlight[] getHighlights();
  104.  
  105.     /**
  106.      * Highlight renderer.
  107.      */
  108.     public interface HighlightPainter {
  109.  
  110.     /**
  111.      * Renders the highlight.
  112.          *
  113.          * @param g the graphics context
  114.          * @param p0 the starting offset in the model >= 0
  115.          * @param p1 the ending offset in the model >= p0
  116.          * @param bounds the bounding box for the highlight
  117.          * @param c the editor
  118.      */
  119.         public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c);
  120.  
  121.     }
  122.  
  123.     public interface Highlight {
  124.  
  125.         /**
  126.          * Gets the starting model offset for the highlight.
  127.          *
  128.          * @return the starting offset >= 0
  129.          */
  130.     public int getStartOffset();
  131.  
  132.         /**
  133.          * Gets the ending model offset for the highlight.
  134.          *
  135.          * @return the ending offset >= 0
  136.          */
  137.     public int getEndOffset();
  138.  
  139.         /**
  140.          * Gets the painter for the highlighter.
  141.          *
  142.          * @return the painter
  143.          */
  144.     public HighlightPainter getPainter();
  145.  
  146.     }
  147.  
  148. };
  149.  
  150.